<%
    var data = data;
%>
  <script>
    var appid = '<%=data.appid%>';
    var timestamp = '<%=data.timestamp%>';
    var nonceStr = '<%=data.noncestr%>';
    var signature = '<%=data.signature%>';
    var share_image = '<%=data.share_image%>';
    var title = '<%=data.title%>';
    var description = '<%=data.desc%>';
    var share_url = '<%=data.url%>';
    var requestUrl = '<%=data.requestUrl%>';

    wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: appid, // 必填，公众号的唯一标识
      timestamp: timestamp, // 必填，生成签名的时间戳
      nonceStr: nonceStr, // 必填，生成签名的随机串
      signature: signature,// 必填，签名，见附录1
      jsApiList: [
        'onMenuShareTimeline',
        'hideMenuItems'
      ]
    });

    wx.ready(function () {
      wx.hideMenuItems({
        menuList: [
          'menuItem:share:appMessage'// 分享到朋友圈
        ]
      });
      wx.onMenuShareTimeline({
        title: title,
        desc: description,
        link: share_url,
        imgUrl: share_image,
        success: function (res) {
          var locationUrl = window.location.href;
          var tttime = new Date().getTime();
          if (locationUrl.indexOf('?') > -1) {
            locationUrl = locationUrl + "&shared=haveShared&tt=" + tttime;
          } else {
            locationUrl = locationUrl + "?shared=haveShared&tt=" + tttime;
          }
          window.location.href = locationUrl;
        },
        fail: function (res) {
          try {
            alert(JSON.stringify(res));
          } catch (error) {
            alert(error.message);
          }
        },
        cancel: function () {
          console.log("取消分享");
        }
      });

    });
    wx.error(function (res) {
      try {
        alert(JSON.stringify(res));
      } catch (error) {
        alert(error.message);
      }
    });
  </script>